﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace Kockicka
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string RndNumber()
        {
            int random = RandomNumber(1, 6);
            string toReturn = random.ToString() +"\nvar nizaNaSliki=new Array();";
            toReturn += "krajnaBrojka="+random.ToString()+";";
            toReturn += "document.getElementById(\'status\').innerHTML=\'Вртам\';";
            toReturn+="for(var i=0;i<5;i++){";
		    toReturn+="a=Math.floor(Math.random()*6)+1;";
            toReturn += "nizaNaSliki[i]=a;}";
            toReturn += "setTimeout(\'animacija(\'+krajnaBrojka+\',0)\',400);";
            toReturn += "function animacija(krajnaBrojka,doKade){";
            toReturn += "if(doKade<5){";
            toReturn += "document.getElementById(\'slika\').src=String(nizaNaSliki[doKade])+\'.png\';";
            toReturn += "setTimeout(\'animacija(\'+krajnaBrojka+\',\'+(doKade+1)+\')\',400);}";
            toReturn += "else{";
            toReturn += "document.getElementById('slika').src=String(krajnaBrojka)+'.png';";
            toReturn += "document.getElementById('status').innerHTML='Свртено. Имаше среќа?';}";
            toReturn += "}";
            
            return toReturn;
        }


        private int RandomNumber(int min, int max)
        {
            Random rnd = new Random();
            return rnd.Next(min, max);
        }
    }
}